home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chess++ ƒ / CChessOptionsDialog.cp < prev    next >
Text File  |  1993-05-26  |  5KB  |  173 lines

  1. ////////////
  2. //
  3. //    CChessOptionsDialog.cp
  4. //
  5. //    A subclass of CDLOGDirector that displays the Chess Options... dialog, 
  6. //    allowing the user to change whatever in the game.
  7. //
  8. //    SUPERCLASS = CDLOGDirector
  9. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  10. //
  11. ////////////
  12.  
  13. #include "CChessOptionsDialog.h"
  14. #include "CChessInfoPane.h"
  15. #include <Commands.h>
  16. #include <CRadioGroupPane.h>
  17. #include <CRadioControl.h>
  18. #include <CIntegerText.h>
  19. #include <CWindow.h>
  20. #include <CBartender.h>
  21. #include "CBrain.h"
  22.  
  23. extern CBartender    *gBartender;
  24. extern CBrain        *gBrain;
  25.  
  26. #define    kChessOptionsDLOGID    1030    // resource ID of the DLOG resource
  27.  
  28.  
  29. /******************************************************************************
  30.  IChessOptionsDialog
  31.  
  32.      Initialize the dialog. This method also assigns help balloon resource
  33.      indexes for some of the panes in the window.
  34.      
  35. ******************************************************************************/
  36.  
  37. void CChessOptionsDialog::IChessOptionsDialog( CDirectorOwner *aSupervisor)
  38. {
  39.     CDLOGDirector::IDLOGDirector( kChessOptionsDLOGID, aSupervisor);
  40. }
  41.  
  42. /******************************************************************************
  43.  SelectDocType
  44.  
  45.      Displays the modal dialog and returns a command number corresponding
  46.      to the user's selection.
  47.      
  48. ******************************************************************************/
  49.  
  50. void CChessOptionsDialog::DoChessOptionsDialog( void)
  51. {
  52.     long             theCommand;
  53.     CRadioGroupPane    *radioGroup;
  54.     CButton            *theButton;
  55.     CIntegerText    *theText;
  56.     register        i;
  57.     short            stationSetting;
  58.     
  59.     itsWindow->SetTitle("\pChess Options");
  60.  
  61.     for (i=kEasyGame;i<=kWayHardGame;i++)
  62.     {
  63.         theButton = (CButton *)itsWindow->FindViewByID(i);
  64.         theButton->SetClickCmd(i);
  65.     }
  66.  
  67.     //    dummy call to force class reference (otherwise CChessInfoPane will be
  68.     //    smart-linked out of existence
  69.     if (i == kEasyGame)    //    always false
  70.         member(theButton,CChessInfoPane);
  71.     
  72.     for (i=kSoundOnBetterMoves;i<=kDoReallyCoolThings;i++)
  73.     {
  74.         theButton = (CButton *)itsWindow->FindViewByID(i);
  75.         theButton->SetClickCmd(i);
  76.     }
  77.     
  78.     // set initial radio group selection. Since this dialog was created
  79.     // from a resource, we don't have a reference to the radio group pane.
  80.     // Since we know its ID (its the same as the dialog item number), we
  81.     // can get the reference by calling FindViewByID.
  82.     
  83.     radioGroup = (CRadioGroupPane*) itsWindow->FindViewByID( kRadioGroupID);
  84.  
  85.     selectedSearchDepth = gBrain->searchDepth;
  86.     radioGroup->SetStationID( selectedSearchDepth+2);
  87.     
  88.     selectedSoundOnBetterMoves = gBrain->soundOnBetterMoves;
  89.     theButton = (CButton *)itsWindow->FindViewByID(kSoundOnBetterMoves);
  90.     theButton->SetValue(selectedSoundOnBetterMoves);
  91.  
  92.     selectedShowThoughts = gBrain->showContemplatedMoves;
  93.     theButton = (CButton *)itsWindow->FindViewByID(kShowThoughts);
  94.     theButton->SetValue(selectedShowThoughts);
  95.  
  96.     selectedBackPropagation = gBrain->backPropagation;
  97.     theButton = (CButton *)itsWindow->FindViewByID(kDoReallyCoolThings);
  98.     theButton->SetValue(selectedBackPropagation);
  99.  
  100.     selectedBackgroundTimeInterval = gBrain->backgroundTimeInterval;
  101.     theText = (CIntegerText *)itsWindow->FindViewByID(kBackgroundTimeInterval);
  102.     theText->SetIntValue(selectedBackgroundTimeInterval);
  103.  
  104.         // show the dialog
  105.         
  106.     BeginDialog();
  107.     
  108.         // run the dialog and return the final command.
  109.         
  110.     theCommand = DoModalDialog( cmdOK);
  111.     
  112.     if (theCommand == cmdOK)
  113.     {
  114.         gBrain->searchDepth = selectedSearchDepth;
  115.         gBrain->soundOnBetterMoves = selectedSoundOnBetterMoves;
  116.         gBrain->showContemplatedMoves = selectedShowThoughts;
  117.         gBrain->backPropagation = selectedBackPropagation;
  118.         selectedBackgroundTimeInterval = theText->GetIntValue();
  119.         gBrain->backgroundTimeInterval = selectedBackgroundTimeInterval;
  120.     }
  121.  
  122.     return;
  123. }
  124.  
  125. void CChessOptionsDialog::DoCommand(long theCommand)
  126.  
  127. {
  128.     Rect            aRect;
  129.     CChessInfoPane    *infoPane = (CChessInfoPane *)itsWindow->FindViewByID(7);
  130.     
  131.     switch (theCommand) {
  132.     
  133.         case kEasyGame:
  134.             infoPane->infoString = kEasyGame;
  135.             selectedSearchDepth = 1;
  136.             break;
  137.         case kHardGame:
  138.             infoPane->infoString = kHardGame;
  139.             selectedSearchDepth = 2;
  140.             break;
  141.         case kWayHardGame:
  142.             infoPane->infoString = kWayHardGame;
  143.             selectedSearchDepth = 3;
  144.             break;
  145.         case kSoundOnBetterMoves:
  146.             infoPane->infoString = kSoundOnBetterMoves;
  147.             if (selectedSoundOnBetterMoves)
  148.                 selectedSoundOnBetterMoves = false;
  149.             else
  150.                 selectedSoundOnBetterMoves = true;
  151.             break;
  152.         case kShowThoughts:
  153.             infoPane->infoString = kShowThoughts;
  154.             if (selectedShowThoughts)
  155.                 selectedShowThoughts = false;
  156.             else
  157.                 selectedShowThoughts = true;
  158.             break;
  159.         case kDoReallyCoolThings:
  160.             infoPane->infoString = kDoReallyCoolThings;
  161.             if (selectedBackPropagation)
  162.                 selectedBackPropagation = false;
  163.             else
  164.                 selectedBackPropagation = true;
  165.             break;
  166.         default:
  167.             inherited::DoCommand(theCommand);
  168.             break;
  169.     }
  170.  
  171.     infoPane->Prepare();
  172.     infoPane->Draw(&aRect);
  173. }